from appium.webdriver.common.appiumby import AppiumBy

from app.page_object.base_page import BasePage


class MemberListPage(BasePage):
    __BTN_ADDMEMBER = (AppiumBy.XPATH, '//*[@text="添加成员"]')
    __BTN_ADDIPU = (AppiumBy.XPATH, "//*[@text='手动输入添加']")
    __TOAST = (AppiumBy.XPATH, '//*[@class="android.widget.Toast"]')
    __BTN_TRIANGLE = (AppiumBy.XPATH,"//*[@text='成都雪山有限公司']/../../../../android.widget.LinearLayout[3]/android.widget.RelativeLayout[2]")
    #点击添加成员的按钮
    def click_add_menber(self):
        self.do_find(self.__BTN_ADDMEMBER).click()
        self.do_find(self.__BTN_ADDIPU).click()
        # self.driver.find_element(AppiumBy.XPATH, '//*[@text="添加成员"]').click()
        # self.driver.find_element(AppiumBy.XPATH, "//*[@text='手动输入添加']").click()
        from app.page_object.add_menmber_page import AddMemberPage
        return AddMemberPage(self.driver)

    #获得保存成功弹窗的信息
    def get_succuss_value(self):
        element = self.do_find(self.__TOAST)
        # element = self.driver.find_element(AppiumBy.XPATH, '//*[@class="android.widget.Toast"]')
        result = element.get_attribute("text")
        return result

    #点击进入到管理通讯录页面
    def click_go_to_branch(self):
        # 定位小按钮
        self.do_find(self.__BTN_TRIANGLE).click()
        # self.driver.find_element(AppiumBy.XPATH,"//*[@text='成都雪山有限公司']/../../../../android.widget.LinearLayout[3]/android.widget.RelativeLayout[2]").click()
        from app.page_object.add_branch_page import AddBranchPage
        return AddBranchPage(self.driver)

    #得到添加的部门的名称
    def get_branch_value(self,branch_name):
        result = self.driver.find_element(AppiumBy.XPATH, f"//*[@text='{branch_name}']")
        return result.text

    #进入到首页
    def go_to_homepage(self):
        self.driver.find_element(AppiumBy.XPATH, "//*[@text='消息']").click()
        from app.page_object.home_page import HomePage
        return HomePage(self.driver)